<template>
	<view class="container">
		<u-navbar title-size="34" title="修改昵称" back-icon-color="#292940"  title-color="#292940" :border-bottom="false" placeholder
			:custom-back="tui.goBack"></u-navbar>
		<view class="form_box pt-3">
			<view class="item">
				<u-input v-model.trim="nickname" :border="false" class="input-box" clearable placeholder="请输入昵称" placeholder-style="color:#E2E2E5;size:32upx">
				</u-input>
			</view>
			<view class="but-box">
				<u-button class="main-bg family-sc fz-36" :loading="loading" hover-class="none" @tap="save">确认</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				nickname: '',
				loading:false
			}
		},
		computed: {
			USER(){
				return this.$store.state.auth.USER
			}
		},
		onLoad() {
			this.nickname = this.USER.nickname
		},
		methods: {
			save() {
				if(this.nickname === ''){
					return uni.$u.toast('请输入昵称')
				}
				this.loading = true
				this.$store.dispatch('user/userUpdate', {nickname:this.nickname}).then(res => {
					this.loading = false
					uni.$u.toast('修改成功')
					this.tui.getUserInfo()
					setTimeout(() => {
						this.tui.goBack()
					}, 1000)
				}).catch(error=>{
					this.loading = false
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		width: 100%;
		min-height: 100vh;
		background: #F8F9FB;

		.form_box {
			width: 100%;
			padding: 0 30upx;
			box-sizing: border-box;
			background: #fff;
		}

		.item {
			height: 140upx;
			box-sizing: border-box;
			padding-top: 56upx;
			border-bottom: 1upx solid rgba(216, 222, 228, .8);
		}

		.input-box {
			width: 100%;
			box-sizing: border-box;
			display: flex;
			justify-content: space-between;
			text-align: left;
			margin-top: 10upx !important;

			input {
				height: 84upx;
				// width: calc(100% - 180upx) !important;
				font-size: 32upx;
				color: #2c2c2c;
			}

			.eye-img {
				width: 36upx;
				height: 36upx;
			}
		}

		.u-border-bottom {
			border-color: #eeeeee !important;
		}

		.but-box {
			width: 100%;
			padding: 80upx 0;

			button {
				width: 100%;
				height: 98upx;
				border-radius: 50upx;
				line-height: 98upx;
				font-size: 32upx;
				color: #FFFFFF;
			}

			uni-button:after {
				border: none !important;
			}
		}

	}
</style>
